package com.example.springmvcdemo.controller;

import com.example.springmvcdemo.entity.MessageWallInfo;
import com.example.springmvcdemo.service.MessageWallService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@ResponseBody
@Controller
@RequestMapping("/message")
public class MessageWallController {
    @Autowired
    private MessageWallService messageWallService;

    private List<MessageWallInfo> MessageWallInfos = new ArrayList<>();

    @RequestMapping("publish")
    public boolean publishMessage(MessageWallInfo messageWallInfo) {
        if (!StringUtils.hasLength(messageWallInfo.getPerson1()) ||
                !StringUtils.hasLength(messageWallInfo.getPerson2()) ||
                !StringUtils.hasLength(messageWallInfo.getMessage())) {
            return false;
        }

        MessageWallInfos.add(messageWallInfo);
        return true;
    }

    @RequestMapping("getList")
    public List<MessageWallInfo> getList() {
        return MessageWallInfos;
    }
}
